from pathlib import Path

def delete_files_from_txt(txt_path):
    """根据文本文件中的路径删除文件"""
    txt_file = Path(txt_path)

    if not txt_file.is_file():
        print(f"文件 {txt_file} 不存在。")
        return

    # 读取文本文件中的路径
    with open(txt_file, 'r', encoding='utf-8') as f:
        paths_to_delete = f.read().splitlines()

    # 删除指定路径的文件
    for path in paths_to_delete:
        file_path = Path(path.strip())  # 去除多余空格
        if file_path.is_file():
            try:
                file_path.unlink()  # 删除文件
                print(f"已删除: {file_path}")
            except Exception as e:
                print(f"删除文件 {file_path} 失败: {e}")
        else:
            print(f"文件不存在: {file_path}")

if __name__ == "__main__":
    txt_file_path = r"D:\Documents\Desktop\删除文件.txt"  # 替换为您的 txt 文件路径
    delete_files_from_txt(txt_file_path)
